{extend name="public/base" /}
{block name="title"}上传文件插件{/block}
{block name="main"}
    
    <div class="layui-input-block">
        <input type="txt" name="pic" value="" id="JS_upImg_input" />
        <div class="e-upload-img" id="JS_upload_img" style="display: none;"><img src="" /></div>                    
        <button  type="button" class="layui-btn" id="JS_upload_btn">上传图片</button>
        
	</div>
 
{/block}

{block name="script"}

<script type="text/javascript" src="/static/admin/lib/webuploader/webuploader.js"></script>
<link rel="stylesheet" href="/static/admin/lib/webuploader/webuploader.css" media="all" />

<script>


layui.use(['webuploader','common','element'],function(){
    var uploader = layui.webuploader;
    
    /*
    layui.layer.open({
          type: 1,
          title: false,
          shadeClose: true, //开启遮罩关闭
          skin: 'layui-layer-demo', //样式类名
          closeBtn: 0, //不显示关闭按钮
          anim: 2,
          content: '<div ><div lay-filter="webuploder"  class="layui-progress" lay-showpercent="true"><div class="layui-progress-bar" lay-percent="20%"></div></div></div>'
    });*/
    
    //layui.element.progress('webuploder', '50%');
    
    
    
    /*
    var id = '#JS_upload_btn';
    var dd = id.replace(/[#\.]/,"");
    console.log( dd );
    
    return false;
    */
    uploader.render({
        elem : '#JS_upload_btn',
        url      : '/test/upload/upfile?filetype=terminal',
        done : function(ret){
            console.log( 'okokk');
            console.log(ret);
        }
    });
    
    
    return true;
    
    $('#JS_upload_btn').after('<div style="display: none;" id="JS_upload_btn_hide"></div>');
    
    $('#JS_upload_btn').on('click',function(){
        $("#JS_upload_btn_hide").find('input[name="file"]').click(); 
    });
    
    var uploader = WebUploader.create({
        pick: {
           id : '#JS_upload_btn_hide',
          // innerHTML : '上传文件'
        },  
        accept: {
		  title:'Images',
		  extensions:'*',// 'png,apk',
		  mimeTypes: '*'
	    },
        auto: true,     
        swf     : '/static/admin/lib/webuploader/webuploader/Uploader.swf',
        server  : '/test/upload/upfile?filetype=terminal',            
        fileVal : 'file',//隐藏域name                   
        chunked: true,  // 开起分片上传。
        fileNumLimit: 300,
      //  fileSizeLimit: 5 * 1024 * 1024,    // 200 M
      //  fileSingleSizeLimit: 10 * 1024 * 1024    // 50 M
        
    });
    console.log(uploader);
    // 当文件被加入队列之前触发
    
    uploader.on( 'beforeFileQueued', function( file) {
        console.log('beforeFileQueued');
        
        //console.log(file.Status);
        //var ret = uploader.upload(file);
        //console.log(ret);
    });
    uploader.on( 'fileQueued', function( file ) {
        console.log('fileQueued');
        /*
        console.log("正在计算MD5值...");
        uploader.md5File(file).then(function (fileMd5) {
            console.log(fileMd5);
            file.wholeMd5 = fileMd5;
            file_md5 = fileMd5;
            console.log("MD5计算完成。");
            console.log("正在查找有无断点...");
            
        });*/
    });
    
    uploader.on('uploadStart',function( file) {
        console.log( 'uploadStart');        
        var now = new Date();    
        var hour = now.getHours().toString();//得到小时
        var minu = now.getMinutes().toString();//得到分钟
        var sec  = now.getSeconds().toString();//得到秒
        var MS   = now.getMilliseconds().toString();//获取毫秒
        console.log(hour+minu+sec+MS);
        file.fileid = hour+minu+sec+MS;        
    });
    
    uploader.on('uploadBeforeSend',function(object ,data,headers){
        console.log('uploadBeforeSend');
        console.log(object);
      //  console.log(data);
        data.fileid = object.file.fileid;
    });
    
    uploader.on('uploadAccept',function(object ,ret){
        console.log('uploadAccept');
        //console.log( object );
        //console.log( ret );
    })
    
    uploader.on( 'error', function( type ) {
        console.log('error');
        console.log(type);
    });
    
    
    
    
});
</script>
{/block}